package com.hongye.backstage.controller;

import com.hongye.backstage.entity.HomeyHouseDetailsEntity;
import com.hongye.backstage.entity.HongyeHouseEntity;
import com.hongye.backstage.entity.HongyeOrderEntity;
import com.hongye.backstage.service.HongyeHouseService;
import com.hongye.common.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @progam:hongye-house
 * @author:GJS
 * @Time:2022/4/20 18:38
 */
@RestController
@RequestMapping("/backstage/house")
public class HongyeHouseController {
    
    @Autowired
    private HongyeHouseService hongyeHouseService;


    /**
     * 房源管理列表
     * @return
     */
    @RequestMapping("/findHouseList")
    public ResponseResult findHouseList(){
        List<HongyeHouseEntity> list = hongyeHouseService.findHouseList();
        ResponseResult<List<HongyeHouseEntity>> listResponseResult = new ResponseResult<>();
        listResponseResult.setCode(200);
        listResponseResult.setData(list);
        listResponseResult.setSuccess(true);
        return listResponseResult;
    }

    /**
     * 房源管理修改
     * @return
     */
    @RequestMapping("/updateHouseList")
    public ResponseResult updateHouseList(@RequestBody HongyeHouseEntity hongyeHouseEntity){
        int i =  hongyeHouseService.updateHouseList(hongyeHouseEntity);
        ResponseResult<Integer> listResponseResult = new ResponseResult<>();

        if (i>0){
            listResponseResult.setCode(200);
            listResponseResult.setData(i);
            listResponseResult.setSuccess(true);
        }else {
            listResponseResult.setCode(500);
            listResponseResult.setData(i);
            listResponseResult.setSuccess(false);
        }
        return listResponseResult;
    }

    /**
     * 房源管理删除
     * @return
     */
    @RequestMapping("/delectHouseList/{hid}")
    public ResponseResult delectHouseList(@PathVariable("hid") Integer hid){
        int i =  hongyeHouseService.delectHouseList(hid);
        ResponseResult<Integer> listResponseResult = new ResponseResult<>();

        if (i>0){
            listResponseResult.setCode(200);
            listResponseResult.setData(i);
            listResponseResult.setSuccess(true);
        }else {
            listResponseResult.setCode(500);
            listResponseResult.setData(i);
            listResponseResult.setSuccess(false);
        }
        return listResponseResult;
    }
    /**
     * 房屋租赁：指定经纪人
     * @return
     */
    @RequestMapping("/updateHouseUid/{hid}/{uid}")
    public ResponseResult updateHouseUid(@PathVariable("hid") Integer hid,@PathVariable("uid") Integer uid){
        int i =  hongyeHouseService.updateHouseUid(hid,uid);
        ResponseResult<Integer> listResponseResult = new ResponseResult<>();

        if (i>0){
            listResponseResult.setCode(200);
            listResponseResult.setData(i);
            listResponseResult.setSuccess(true);
        }else {
            listResponseResult.setCode(500);
            listResponseResult.setData(i);
            listResponseResult.setSuccess(false);
        }
        return listResponseResult;
    }


    /**
     * 房源管理列表
     * @return
     */
    @RequestMapping("/findUserList")
    public ResponseResult findUserList(){
        List<HongyeHouseEntity> list = hongyeHouseService.findHouseList();
        ResponseResult<List<HongyeHouseEntity>> listResponseResult = new ResponseResult<>();
        listResponseResult.setCode(200);
        listResponseResult.setData(list);
        listResponseResult.setSuccess(true);
        return listResponseResult;
    }


    /**
     * 批量添加房屋信息
     */
    @RequestMapping("/addHouse")
    public void addHouse(@RequestBody List<HongyeHouseEntity> list){
        hongyeHouseService.addHouse(list);
    }


    /**
     * 买房列表-详情
     * @return
     */
    @RequestMapping("/findHouse")
    public ResponseResult findHouse(){
        List<HomeyHouseDetailsEntity> list = hongyeHouseService.findHouse();
        ResponseResult<List<HomeyHouseDetailsEntity>> listResponseResult = new ResponseResult<>();
        listResponseResult.setCode(200);
        listResponseResult.setData(list);
        listResponseResult.setSuccess(true);
        return listResponseResult;
    }
}
